﻿<%@ Control Language="VB" AutoEventWireup="false" CodeFile="List.ascx.vb" Inherits="Control_Product_List" %>
<%@ Register TagPrefix="aspNewControls" Namespace="NewControls" %>
<script type='text/javascript'>
    function ajaxJquery() {

        $(function () {

            $(".TextBox:first").focus();
            $("#<%=txtCreatedFrom.ClientID %>").datepicker({ dateFormat: 'dd/mm/yy' });
            $("#<%=txtCreatedTo.ClientID %>").datepicker({ dateFormat: 'dd/mm/yy' });
            $("#<%=txtPublisheddateFrom.ClientID %>").datepicker({ dateFormat: 'dd/mm/yy' });
            $("#<%=txtPublisheddateTo.ClientID %>").datepicker({ dateFormat: 'dd/mm/yy' });

             //check cookie to show or hide search pannel
            if ($.cookie('CookieSiteSearch') == 1) {
                $('#pnlSearch').show();
            }
            else {
                $('#pnlSearch').hide();
            }

            $('#B1').click(function (event) {

                //set cookie
                if ($.cookie('CookieSiteSearch') == 1) {
                    $.cookie('CookieSiteSearch', 0)
                }
                else {
                    $.cookie('CookieSiteSearch', 1)
                }
                $('#pnlSearch').slideToggle(500);
                if ($('#imgShowHide').attr("src") == "../../images/arrow_popup.gif") {
                    $('#imgShowHide').attr("src", "../../images/arrow_showless.gif");
                }
                else {
                    $('#imgShowHide').attr("src", "../../images/arrow_popup.gif");
                }
            });
            $(".SubjectTitle input, .SubjectTitle select").keypress(function (e) {
                if (e.keyCode == 13) {
                    $("#<%=btnSearch.ClientID()%>").click();
                    return false;
                }
            });
        });
    }
 
    function confirmMultiDelete(strID) {
        var grdShow = document.getElementById("<%=grdShow.ClientID %>");
        var count = 0;
        for (i = 1; i < grdShow.children.item(0).children.length; i++) {
            if (grdShow.children.item(0).children.item(i).children.item(0).children.item(0).checked) {
                count += 1;
            }
        }
        if (count > 0) {
            return ComfirmDialog('<%=drpMessage.Items(1).Text%>', 0, strID, 0, 0);
        } else {
            Alertbox('<%=drpMessage.Items(2).Text%>');
            return false;
        }
    }
    function ComfirmDialog(strText, value, ObjectIdClick, ID, Type) {
        if (value == 0) {
            Confirmbox(strText, value, ObjectIdClick, ID, Type);
            return false;
        } else {
            if (Type == 1) {
                document.getElementById('<%=hidID.ClientID %>').value = ID;
                eval($("#" + ObjectIdClick + "").attr("href"));
            }
            else {

                $("#" + ObjectIdClick + "").click();
            }
        }
    }
    //Check ngày đến có lớn hơn ngày bắt đầu hay không
    function CheckDateThanEqual(source, arguments) {
        //So sanh ngay
        if ($("#<%=txtCreatedFrom.ClientID %>").val() != "" && $("#<%=txtCreatedTo.ClientID %>").val() != "") {
            var objFrom = $("#<%=txtCreatedFrom.ClientID %>").val().split('/');
            var objEnd = $("#<%=txtCreatedTo.ClientID %>").val().split('/');
            var FromDate = new Date(objFrom[2], objFrom[1], objFrom[0], 0, 0, 0)
            var EndDate = new Date(objEnd[2], objEnd[1], objEnd[0], 0, 0, 0)

            if (EndDate < FromDate) {
                arguments.IsValid = false;
                return false;
            }
            else {
                arguments.IsValid = true;
                return true;
            }
        }
        else {
            arguments.IsValid = true;
            return true;
        }

      
    }

    function CheckPublishDateThanEqual(source, arguments) {
        if ($("#<%=txtPublisheddateFrom.ClientID %>").val() != "" && $("#<%=txtPublisheddateTo.ClientID %>").val() != "") {
            var objFrom = $("#<%=txtPublisheddateFrom.ClientID %>").val().split('/');
            var objEnd = $("#<%=txtPublisheddateTo.ClientID %>").val().split('/');
            var FromDate = new Date(objFrom[2], objFrom[1], objFrom[0], 0, 0, 0)
            var EndDate = new Date(objEnd[2], objEnd[1], objEnd[0], 0, 0, 0)

            if (EndDate < FromDate) {
                arguments.IsValid = false;
                return false;
            }
            else {
                arguments.IsValid = true;
                return true;
            }
        }
        else {
            arguments.IsValid = true;
            return true;
        }
    }

</script>
<asp:UpdatePanel ID="uplProduct" runat="server">
    <ContentTemplate>
        <div class="BoxField">
            <div class="HeadTitle">
                <h3>
                    QUẢN LÝ SẢN PHẨM</h3>
            </div>
             <div class="Error">
                    <asp:ValidationSummary ID="ValidationSummary1" runat="server" ForeColor="#FF3300" />
                </div>
          
              <div class="SubjectTitle" id="SInfor" runat="server">
            <legend class="SubjectTitle">
                <img alt="" src="../../images/arrow_showless.gif" id="imgShowHide" />
                <a id="B1" href="#">Tìm kiếm </a>&nbsp;&nbsp;</legend>
        </div>
            <div id="pnlSearch" class="SubjectTitle">
                <div id="search" class="BoxField">
                    <div class="DivRow">
                        <div class="DivLabelSearch">
                            Tên sản phẩm:
                        </div>
                        <div class="DivTextBox">
                            <asp:TextBox ID="txtTitle" CssClass="TextBox" runat="server" Text="" />
                        </div>
                    </div>
                    <div style="clear: both">
                    </div>
                    <div class="DivRow">
                        <div class="DivLabelSearch">
                            Mã sản phẩm:
                        </div>
                        <div class="DivTextBox">
                            <asp:TextBox ID="txtCode" CssClass="TextBox" runat="server" Text="" />
                        </div>
                    </div>
                    <div style="clear: both">
                    </div>
                    <div   class="DivRow">
                        <div class="DivLabelSearch">
                            Gian hàng:
                        </div>
                        <div class="DivTextBox">
                            <asp:DropDownList ID="ddlStore" runat="server" CssClass="TextBox" 
                                Width="253px">
                            </asp:DropDownList>
                        </div>
                    </div>
                    <div class="DivRow">
                        <div class="DivLabelSearch">
                            Loại sản phẩm:
                        </div>
                        <div class="DivTextBox">
                            <aspnewcontrols:newdropdownlist id="ddlType" runat="server" cssclass="TextBox"
                                width="253px">
                         </aspnewcontrols:newdropdownlist>
                        </div>
                    </div>
                    <div style="clear: both">
                    </div>
                    <div class="DivRow">
                        <div class="DivLabelSearch">
                            Ngày tạo:
                        </div>
                        <div class="DivTextBox">
                            <asp:TextBox ID="txtCreatedFrom" CssClass="TextBox" runat="server" Text="" 
                                Width="95px" /> 
                            &nbsp;tới ngày    
                            <asp:TextBox ID="txtCreatedTo" CssClass="TextBox" runat="server" 
                                Text="" Width="95px" /> 
                            <asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" 
                                ControlToValidate="txtCreatedFrom" Display="None" 
                                ErrorMessage="Ngày tạo bắt đầu không đúng định dạng" 
                                ValidationExpression="^(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/((19|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/((19|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/((19|[2-9]\d)\d{2}))|(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$"></asp:RegularExpressionValidator>
                            <asp:RegularExpressionValidator ID="RegularExpressionValidator4" runat="server" 
                                ControlToValidate="txtCreatedTo" Display="None" 
                                ErrorMessage="Ngày tạo cuối không đúng định dạng" 
                                ValidationExpression="^(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/((19|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/((19|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/((19|[2-9]\d)\d{2}))|(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$"></asp:RegularExpressionValidator>
                            <asp:CustomValidator ID="CustomValidator1" runat="server" 
                                ClientValidationFunction="CheckDateThanEqual" ControlToValidate="txtCreatedTo" 
                                Display="None" ErrorMessage="Ngày tạo bắt đầu phải nhỏ hơn ngày kết thúc." 
                                SetFocusOnError="false"></asp:CustomValidator>
                        </div>
                    </div>
                    <div style="clear: both">
                    </div>
                    <div class="DivRow">
                        <div class="DivLabelSearch">
                            Người tạo:
                        </div>
                        <div class="DivTextBox">
                            <asp:TextBox ID="txtCreatorid" CssClass="TextBox" runat="server" Text="" />
                        </div>
                    </div>
                    <div style="clear: both">
                    </div>
                    <div class="DivRow">
                        <div class="DivLabelSearch">
                           Hot :
                        </div>
                        <div class="DivTextBox">
                            
                            <asp:DropDownList ID="chkIshot" runat="server" CssClass="TextBox">
                                <asp:ListItem Value="-1" Selected="True">--- Tất cả ---</asp:ListItem>
                                <asp:ListItem Value="1">Có</asp:ListItem>
                                <asp:ListItem Value="0">Không</asp:ListItem>
                        </asp:DropDownList>
                        </div>
                    </div>
                    <div style="clear: both">
                    </div>
                    <div class="DivRow">
                        <div class="DivLabelSearch">
                            Khuyến mại:
                        </div>
                        <div class="DivTextBox">
                          
                              <asp:DropDownList ID="chkIsselloff" runat="server" CssClass="TextBox">
                                <asp:ListItem Value="-1" Selected="True">--- Tất cả ---</asp:ListItem>
                                <asp:ListItem Value="1">Có</asp:ListItem>
                                <asp:ListItem Value="0">Không</asp:ListItem>
                        </asp:DropDownList>
                        </div>
                    </div>
                    <div style="clear: both">
                    </div>
                    <div class="DivRow">
                        <div class="DivLabelSearch">
                            Trang thái:
                        </div>
                        <div class="DivTextBox">
                            <asp:DropDownList ID="ddlStatus" runat="server" CssClass="TextBox" 
                                Width="253px">
                            </asp:DropDownList>
                        </div>
                    </div>
                    <div style="clear: both">
                    </div>
                    <div class="DivRow">
                        <div class="DivLabelSearch">
                            Ngày xuất bản:
                        </div>
                        <div class="DivTextBox">
                            <asp:TextBox ID="txtPublisheddateFrom" CssClass="TextBox" runat="server" Text="" 
                                Width="95px" /> tới ngày:  <asp:TextBox ID="txtPublisheddateTo" 
                                CssClass="TextBox" runat="server" Text="" 
                                Width="95px" />
                            <asp:RegularExpressionValidator ID="RegularExpressionValidator5" runat="server" 
                                ControlToValidate="txtPublisheddateFrom" Display="None" 
                                ErrorMessage="Ngày xuất bản bắt đầu không đúng định dạng" 
                                ValidationExpression="^(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/((19|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/((19|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/((19|[2-9]\d)\d{2}))|(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$"></asp:RegularExpressionValidator>
                            <asp:RegularExpressionValidator ID="RegularExpressionValidator6" runat="server" 
                                ControlToValidate="txtPublisheddateTo" Display="None" 
                                ErrorMessage="Ngày  xuất bản cuối không đúng định dạng" 
                                ValidationExpression="^(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/((19|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/((19|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/((19|[2-9]\d)\d{2}))|(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$"></asp:RegularExpressionValidator>
                            <asp:CustomValidator ID="CustomValidator2" runat="server" 
                                ClientValidationFunction="CheckPublishDateThanEqual" 
                                ControlToValidate="txtPublisheddateTo" Display="None" 
                                ErrorMessage="Ngày xuất bản bắt đầu phải nhỏ hơn ngày kết thúc." 
                                SetFocusOnError="false"></asp:CustomValidator>
                        </div>
                    </div>
                    <div style="clear: both">
                    </div>
                    <div class="DivRow">
                        <div class="DivLabelSearch">
                            &nbsp;&nbsp;&nbsp;</div>
                        <div class="DivTextBox">
                            <asp:Button ID="btnSearch" runat="server" Text=" Tìm kiếm" CssClass="btn" />
                            <asp:Button ID="btnReset" runat="server" Text="Hủy" CssClass="btn" 
                                CausesValidation="False" />&nbsp;
                        </div>
                    </div>
                    <div style="clear: both; height: 10px">
                    </div>
                </div>
            </div>
            
            <asp:GridView ID="grdShow" runat="server" AutoGenerateColumns="False" EmptyDataText="{Không có dữ liệu}"
                Width='100%' BorderWidth="1px" CssClass="GridBorder">
                <Columns>
                    <asp:TemplateField>
                        <HeaderTemplate>
                            <asp:CheckBox ID="CheckAll" runat="server" onclick="CheckAll(this)" Width="30px" />
                        </HeaderTemplate>
                        <HeaderStyle HorizontalAlign="Center" />
                        <ItemTemplate>
                            <asp:CheckBox ID="chkItem" runat="server" />
                        </ItemTemplate>
                        <ItemStyle Width="5%" HorizontalAlign="Center" />
                    </asp:TemplateField>
                    <asp:TemplateField>
                        <ItemTemplate>
                            <asp:HyperLink ID="hplEdit" runat="server" Text="Sửa"></asp:HyperLink>&nbsp;|&nbsp;
                            <asp:LinkButton ID="lnkbtnDelete" Text="Xóa" runat="server" OnClick="lnkbtnDelete_Click"
                                CausesValidation='False'></asp:LinkButton>
                        </ItemTemplate>
                        <ItemStyle CssClass="GridTextLink" HorizontalAlign="Center" Width="10%" />
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="No">
                        <ItemTemplate>
                            <asp:Label runat="server" ID="lblSTT" Text=''></asp:Label>
                        </ItemTemplate>
                        <ItemStyle Width="5%" HorizontalAlign="Left" />
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText='Tên sản phẩm'>
                        <ItemTemplate>
                            <asp:HyperLink ID="hplTitle" runat="server"></asp:HyperLink>
                        </ItemTemplate>
                        <ItemStyle Width='12%' CssClass='text_list_links' HorizontalAlign='Left' />
                    </asp:TemplateField>

                    <asp:BoundField DataField='Code' HeaderText='Mã'>
                        <ItemStyle Width='7%' />
                    </asp:BoundField>

                    <asp:TemplateField HeaderText='Giá'>
                        <ItemTemplate>
                            <asp:TextBox ID="txtOriginalPrice" runat="server" Width="70px"></asp:TextBox>
                        </ItemTemplate>
                        <ItemStyle Width="7%" HorizontalAlign="Right" />
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText='Loại'>
                        <ItemTemplate>
                            <asp:HyperLink ID="hplCategory" runat="server"></asp:HyperLink>
                        </ItemTemplate>
                        <ItemStyle Width='7%' CssClass='text_list_links' HorizontalAlign='Left' />
                    </asp:TemplateField>

                    <asp:BoundField DataField='Created' DataFormatString="{0:dd/MM/yyyy HH:mm}" HeaderText='Ngày tạo'>
                        <ItemStyle Width='10%' />
                    </asp:BoundField>
                    <asp:BoundField DataField='Creator' HeaderText='Người tạo'>
                        <ItemStyle Width='8%' />
                    </asp:BoundField>


                    <asp:TemplateField HeaderText='Số lượng'>
                        <ItemTemplate>
                            <asp:HyperLink ID="hplSoLuong" runat="server"></asp:HyperLink>
                        </ItemTemplate>
                        <ItemStyle Width="15%" HorizontalAlign="Right" />
                    </asp:TemplateField>


                    <asp:BoundField DataField='StatusName' HeaderText='Trạng thái'>
                        <ItemStyle Width='10%' />
                    </asp:BoundField>



                </Columns>
                <HeaderStyle Height="26px" HorizontalAlign="Left" CssClass="GridHeader" />
                <RowStyle CssClass="GridRow" Height="23px" />
                <AlternatingRowStyle CssClass="GridAlterRow" />
                <PagerStyle CssClass="GridPaged" HorizontalAlign="Right" Height="23px" />
                <PagerSettings Mode="Numeric" PageButtonCount="2" />
                <EmptyDataRowStyle CssClass="GridTextEmpty" HorizontalAlign="Center" />
            </asp:GridView>
            <div>
                
                <asp:Button ID="btnDelete" CssClass="btn" runat="server" Text="Xóa" />
                <asp:Button ID="btnPublish" CssClass="btn" runat="server" Text="Trạng Thái" CausesValidation="false" />
                <asp:Button ID="btnUpdate" CssClass="btn" runat="server" Text="Update Giá" CausesValidation="false"  />
                <asp:Button ID="btnImportExcel" CssClass="btn" runat="server" Text="Import Excel" CausesValidation="false" />

                <asp:Label ID="lblPage_Size" runat="server" Text="Số bản ghi trên trang:"></asp:Label>
                <asp:DropDownList ID="drpPage_Size" runat="server" AutoPostBack="True" Width="70px"
                    CssClass="input_form">
                    <asp:ListItem Text="100" Value="100"></asp:ListItem>
                    <asp:ListItem Text="20" Value="20"></asp:ListItem>
                    <asp:ListItem Text="50" Value="50"></asp:ListItem>
                    <asp:ListItem Text="200" Value="200"></asp:ListItem>
                </asp:DropDownList>
                <asp:Label ID="lblTotal" runat="server"></asp:Label></div>
            <div style="width: 100%">
                <!--phan trang-->
                <div id="results_resultsNavigationDiv" class="paginationEMP">
                    <ul>
                        <asp:LinkButton ID="lnkFirst" runat="server"></asp:LinkButton>
                        <asp:Repeater ID="rptPage" runat="server">
                            <ItemTemplate>
                                <asp:LinkButton ID="lnkTitle" CssClass="page_num" runat="server" OnClick="lnkTitle_Click"></asp:LinkButton>
                            </ItemTemplate>
                        </asp:Repeater>
                        <asp:LinkButton ID="lnkLast" runat="server"></asp:LinkButton>
                    </ul>
                </div>
                <asp:HiddenField ID="hidCount" Value="0" runat="server" />
                <asp:HiddenField ID="hidIndex_page" Value="0" runat="server" />
                <asp:HiddenField ID="hidCur_Page" Value="1" runat="server" />
            </div>
            <div style='display: none'>
                <asp:DropDownList ID="drpMessage" runat="server">
                    <asp:ListItem Text='Bạn có chắc chắn muốn xóa bản ghi này không?' Value='0'></asp:ListItem>
                    <asp:ListItem Text='Bạn có chắc chắn muốn xóa bản đã chọn?' Value='1'></asp:ListItem>
                    <asp:ListItem Text='Bạn phải chọn ít nhất một bản ghi.' Value='2'></asp:ListItem>
                </asp:DropDownList>
                <asp:HiddenField ID="hidID" Value="0" runat="server" />
            </div>
        </div>
    </ContentTemplate>
</asp:UpdatePanel>
